<template>
  <main>
    <header>
      <h2>实现模态框</h2>
    </header>
    <section>
      <p><strong>实现以下效果和逻辑：</strong></p>
      <p>点击按钮，弹出模态框并展示内容，并在中间生成半透明蒙板，点击蒙板或者确定按钮都可以关闭模态框，同时将关闭模态框的行为方式显示在页面下方。</p>
      <p>注意事项：可以使用已掌握的任何技术，保持思路清晰和代码风格一致。最好能提供渐变动画。</p>
      <article>
        <button @click="showModal">点击我弹出模态框</button>
        <p>{{ info }}</p>
      </article>
    </section>

    <div class="modal" :class="{ active: isShow }">
      <div class="mask" @click="clickMask"></div>
      <div class="inner">
        <div class="modal-header">
          <h3>模态框</h3>
        </div>
        <div class="content">
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
          <p>这里是内容</p>
        </div>
        <div class="modal-footer">
          <button @click="clickConfirm">确定</button>
        </div>
      </div>
    </div>
  </main>
</template>

<script>
export default {
  data () {
    return {
      isShow: false,
      info: ''
    }
  },
  methods: {
    showModal () {
      this.isShow = true
      this.info = ''
    },
    clickMask () {
      this.isShow = false
      this.info = '关闭方式：点击蒙板'
    },
    clickConfirm () {
      this.isShow = false
      this.info = '关闭方式：点击确定'
    }
  }
}
</script>


<style scoped>
section {
  flex: auto;
  padding: 0 8vw;
  text-align: left;
}
article {
  margin-top: 80px;
}

button {
  font-size: 15px;
  background-color: #25a5e0;
  color: #fff;
  border: none;
  padding: 8px 10px;
  text-align: center;
  min-width: 5em;
  cursor: pointer;
}

.modal {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.modal.active {
  pointer-events: auto;
}
.modal .mask {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: all 0.3s ease-in;
}
.modal.active .mask {
  opacity: 1;
}
.modal .inner {
  min-width: 40%;
  min-height: 50%;
  max-width: 80%;
  max-height: 80%;
  background-color: #fff;
  position: relative;
  z-index: 10;
  border-radius: 5px;
  transform: translateY(-30px);
  transition: all 0.3s ease-in;
  opacity: 0;
}
.modal.active .inner {
  transform: translateY(0);
  opacity: 1;
}
.modal .inner {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.modal .inner .content {
  flex: auto;
  overflow-y: auto;
  width: 100%;
  padding: 20px;
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  box-sizing: border-box;
}
.modal .inner .modal-footer {
  padding: 20px;
}
</style>

